import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';
import {toast} from 'nc-lightapp-front'
import deleteLine from "./deleteLine";
//hi_psndoc_deptchg/hi_psndoc_part/hi_psndoc_dimission取行上的pk_psnjob,其他的取pk_psndoc_sub
const mainTables = ['hi_psndoc_deptchg', 'hi_psndoc_part', 'hi_psndoc_dimission'];

export default function checkDeleteLine(record, index) {
    const {areaCode} = this.state;
    const {selectedPsn, orgVal, func_type} = this.props;

    const pkField = mainTables.indexOf(areaCode) > -1 ? 'pk_psnjob' : 'pk_psndoc_sub';
    const pk_sub = record.values[pkField].value;

    let postData = {
        areaCode,
        func_type,
        pk_org: orgVal.refpk,
        pk_psnjob: selectedPsn,
        pk_sub
    };

    return proFetch({
        url: '/nccloud/hrtrn/pub/RecordsDelLineCheckAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                const {confirmMsg, warningMsg} = res.data;
                this.alertModalNode.show(confirmMsg, warningMsg, () => {
                    deleteLine.call(this, record, index);
                })
            }
        });
}
